package com.bigshen.demo.annotation.configurecomponents.a1ComponentScan;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * 自定义扫描规则
 */
public class MatchedFilter implements TypeFilter {

    /**
     *
     * @param metadataReader  类的信息
     * @param metadataReaderFactory  spring上下文
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

        // 当前类注解的信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        // 当前类的信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        // 当前资源信息
        Resource resource = metadataReader.getResource();

        String clazzName = classMetadata.getClassName();
        System.out.println("--------- " + clazzName);

        if (clazzName.contains("er")){
            return true;
        }
        return false;
    }

}
